<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Init Model
 *
 */


class Category_model extends CI_Model {
	
	function __construct(){
		parent::__construct();
		
		$config = array('table'=>'category_tree');
		$this->load->library('mahana_hierarchy');
		$this->mahana_hierarchy->initialize($config);
		
	}
	
	
	//--Get Category--//
	function getCetegory($parent_id=0, $limit=100){
		
		//$parent_id = (int) $parent_id;
		$sql="select * from category_tree where parent_id=$parent_id order by (name) ASC limit 0,$limit";
		//die ($sql);
		
		$result = $this->db->query($sql)->result();
		
		if ($result){
			return $result;
		} else {
			return false;
		}
	}
	
	//--Get Category info--ypgov//
	function getCategory_info($catID){
		$sql="select * from category_tree where id=$catID limit 1";
		$query = $this->db->query($sql);
		$result = $query->row();
		if ($query->num_rows() > 0){
			return $result;
		} else {
			return false;
		}
	}
	
	//-- GET LISTING --TAG LINK---//
	public function getTagLink($profileID=0, $limit=99){
		$sql = "select term_value from term where listing_id = $profileID and term = 'key' limit 2, $limit";
		$result = $this->db->query($sql)->result();
		$link='';
		
		if($result){
				
			foreach ($result as $key){
				$n = $this->getCategory_info($key->term_value)->name;
				$u = base_url()."browse/practice/".$this->commoncall->url($n)."-".$key->term_value;
				$link.="<a class='text-muted' href=$u>". $n." </a>, ";
			}
			
			$length = strlen(trim($link));
			$link = substr_replace($link, '', $length - 1, $length);
			return $link;	
				
		}else{
			return null;
		}
	}
	
}
/* End of file*/	